package com.czzapp.xiaoyumemo.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//按照Memo的DelayDate进行排序，插入和删除的操作将按照二分搜索法提高效率
public class MemoList {
	public List<Memo> MemoList = new ArrayList<Memo>();
	
	public MemoList() {
		MemoList = new ArrayList<Memo>();
	}
	
	//返回false表示已经有相同的Memo（delayDate和reqId相同）
	public boolean sortedAdd(Memo memo) {
		int index = Collections.binarySearch(MemoList, memo);
		if(index < 0) {
			index = -(index + 1);
			MemoList.add(index, memo);
			return true;
		}
		else {
			return false;
		}
	}
	
	public boolean sortedRemove(Memo memo) {
		int index = Collections.binarySearch(MemoList, memo);
		if(index >= 0) {
			MemoList.remove(index);
			return true;
		}
		else {
			return false;
		}
	}
}
